<template>
  <div class="myCollect">
    <back-nav
      :leftArrow="true"
      :title="'我的收藏'"
      :leftText="'返回'"
    ></back-nav>
    <div class="box">
      <div class="palcehode"></div>
      <div class="collectBox">
        <div class="collectItem">
          <div class="item" v-for="(item, index) in collectArr" :key="index">
            <div class="img">
              <img :src="item.smallImg" class="auto-img" />
            </div>
            <div class="zn-name">{{ item.name }}</div>
            <div class="en-name">{{ item.enname }}</div>
            <div class="priceAndIcon">
              <div class="price">￥{{ item.price }}</div>
              <div class="icon" @click="nolike(item)">
                <img src="../assets/images/sc.png" class="auto-img" />
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
import backNav from "../components/BackNav.vue";
export default {
  name: "myCollect",
  data() {
    return {
      collectArr: [],
    };
  },
  components: {
    backNav,
  },
  methods: {
    // 查看自己收藏的商品
    getCollect() {
      this.axios({
        method: "get",
        url: "/findAllLike",
      })
        .then((res) => {
          console.log(res);
          if (res.data.code == 2000) {
            this.collectArr = res.data.result;
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
    // 取消收藏
    nolike(data) {
      let pid = data.pid;
      this.axios({
        method: "post",
        url: "/notlike",
        data: {
          pid,
        },
      })
        .then((res) => {
          console.log(res);
          if (res.data.code === 900) {
            this.$toast(res.data.msg);
            this.$router.go(0);
          }
        })
        .catch((err) => {
          console.log(err);
        });
    },
  },
  created() {
    this.getCollect();
  },
};
</script>
<style lang="less" scoped>
@import url("../assets/base.less");
.box {
  position: absolute;
  top: 46px;
  bottom: 0px;
  width: 100%;
  overflow-y: auto;
  .palcehode {
    height: 100px;
    width: 100%;
    background-color: @mainColor;
  }
  .collectBox {
    padding: 0px 10px;
    transform: translateY(-20px);
    .collectItem {
      border-radius: 10px 10px 0px 0px;
      height: 195px;
      width: 355px;
      background-color: #fff;
      display: flex;
      flex-wrap: wrap;
      .item {
        flex: 0 0 33.33%;
        padding: 10px 8px;
        box-sizing: border-box;
        .img {
          height: 100px;
          width: 100%;
        }
        .zn-name {
          font-size: 12.5px;
          margin-top: 10px;
        }
        .en-name {
          margin-top: 5px;
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 1;
          -webkit-box-orient: vertical;
        }
        .priceAndIcon {
          margin-top: 10px;
          display: flex;
          .price {
            font-size: 12.5px;
            font-weight: bold;
            color: @mainColor;
          }
          .icon {
            height: 20px;
            width: 20px;
            margin-left: auto;
          }
        }
      }
    }
  }
}
</style>